/
PurgeDeletedUsers.cs
77 lines (69 loc) · 3.37 KB
/
PurgeDeletedUsers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Services.Users
{
using System;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Scheduling;
public class PurgeDeletedUsers : SchedulerClient
{
/// <summary>Initializes a new instance of the <see cref="PurgeDeletedUsers"/> class.</summary>
/// <param name="objScheduleHistoryItem"></param>
public PurgeDeletedUsers(ScheduleHistoryItem objScheduleHistoryItem)
{
this.ScheduleHistoryItem = objScheduleHistoryItem;
}
/// <inheritdoc/>
public override void DoWork()
{
try
{
foreach (PortalInfo portal in new PortalController().GetPortals())
{
var settings = new PortalSettings(portal.PortalID);
if (settings.DataConsentActive)
{
if (settings.DataConsentUserDeleteAction == PortalSettings.UserDeleteAction.DelayedHardDelete)
{
var thresholdDate = DateTime.Now;
switch (settings.DataConsentDelayMeasurement)
{
case "h":
thresholdDate = DateTime.Now.AddHours(-1 * settings.DataConsentDelay);
break;
case "d":
thresholdDate = DateTime.Now.AddDays(-1 * settings.DataConsentDelay);
break;
case "w":
thresholdDate = DateTime.Now.AddDays(-7 * settings.DataConsentDelay);
break;
}
var deletedUsers = UserController.GetDeletedUsers(portal.PortalID);
foreach (UserInfo user in deletedUsers)
{
if (user.LastModifiedOnDate < thresholdDate && user.RequestsRemoval)
{
UserController.RemoveUser(user);
this.ScheduleHistoryItem.AddLogNote(string.Format("Removed user {0}{1}", user.Username, Environment.NewLine));
}
}
}
}
}
this.ScheduleHistoryItem.Succeeded = true; // REQUIRED
this.ScheduleHistoryItem.AddLogNote("Purging deleted users task completed");
}
catch (Exception exc)
{
this.ScheduleHistoryItem.Succeeded = false; // REQUIRED
this.ScheduleHistoryItem.AddLogNote(string.Format("Purging deleted users task failed: {0}.", exc.ToString()));
// notification that we have errored
this.Errored(ref exc); // REQUIRED
// log the exception
Exceptions.Exceptions.LogException(exc); // OPTIONAL
}
}
}
}